from enum import Enum


# release data-manager/src/main/java/com/zdrive/bigdata/platform/common/enums/data/AnnotateTypeEnum.java
class AnnotateTypeEnum(Enum):
    D2_LANE = (1, "2d_lane", "2D车道线", "只需要每帧的 Camera0 和 Camera1")
    D3_LANE = (2, "3d_lane", "3D车道线", "只需要 Clip 的超大融合点云（200帧点云拼接)")
    D23_OBJECT = (3, "23d_object", "23D融合", "需要每帧的1个拼接的点云 + 7个相机")
    D3_BOX = (4, "3d_box", "3D BOX", "需要每帧的1个拼接的点云 + 7个相机")
    D2_TRAFFIC_LIGHT_KEY_FRAME = (
        5,
        "2d_traffic_light_key_frame",
        "2D红绿灯关键帧",
        "2D 红绿灯关键帧 - front main",
    )
    D2_TRAFFIC_LIGHT_CONTINUOUS_FRAME = (
        6,
        "2d_traffic_light_continuous_frame",
        "2D红绿灯连续帧",
        "2D 红绿灯连续帧",
    )
    D23_CITY_OBJECT_DETECTION = (
        7,
        "23d_city_object_detection",
        "23D城市物体检测",
        "23D 城市物体检测",
    )
    M2_D3_CITY_OBJECT_DETECTION = (
        8,
        "m2_3d_city_object_detection",
        "M2 3D城市物体检测",
        "",
    )
    ONLY_D3_CITY_OBJECT_DETECTION = (
        9,
        "only_3d_city_object_detection",
        "Only 3D城市物体检测",
        "",
    )
    D23_OBJECT_DETECTION = (10, "23d_object_detection", "23D物体检测", "")
    BEV_LANE_COMBINE = (11, "bev_lane_combine", "Bev Combine车道线", "")
    CAMERA_BEV_LANE_COMBINE = (
        12,
        "camera_bev_lane_combine",
        "Camera Bev Combine车道线",
        "",
    )
    CAMERA_SLAM_LANE_COMBINE = (
        13,
        "camera_slam_lane_combine",
        "Camera Slam Combine车道线",
        "",
    )
    KEY_POINTS = (14, "key_points", "Key Points关键点", "")
    D3_CITY_OBJECT_DETECTION_WITH_FISH_EYE = (
        15,
        "3d_city_object_detection_with_fish_eye",
        "3D城市物体检测With鱼眼",
        "",
    )
    D3_HIGHWAY_OBJECT_DETECTION_WITH_FISH_EYE = (
        16,
        "3d_highway_object_detection_with_fish_eye",
        "3D高速物体检测With鱼眼",
        "",
    )
    PARKING_MOVABLE_OBJECT_DETECTION = (
        17,
        "parking_movable_object_detection",
        "泊车移动目标物检测",
        "",
    )
    AUTO_4D_LANE = (18, "auto_4d_lane", "AUTO_4D_LANE", "")
    PARKING_SURROUND_SPACE_DETECTION = (
        19,
        "parking_surround_space_detection",
        "环视泊车车位检测",
        "",
    )
    PARKING_ROAD_SIGN_MARK = (20, "parking_road_sign_mark", "泊车路面标识", "")
    PARKING_FREE_SPACE = (21, "parking_free_space", "泊车可行驶区域", "")
    DRIVING_FREE_SPACE = (22, "driving_free_space", "行车可行驶区域", "")
    GOP_OBJECT_DETECTION = (23, "gop_object_detection", "GOP 目标物检测", "")
    CAMERA_2D_BLOCKAGE = (24, "camera_2d_blockage", "相机遮挡", "")
    CAMERA_2D_ENVIRONMENT_IDENTIFICATION = (
        25,
        "camera_2d_environment_identification",
        "环境识别",
        "",
    )
    CAMERA_2D_FSLINE = (26, "camera_2d_fsline", "泊车FSline", "")
    CAMERA_2D_TRAFFIC_SIGN = (27, "camera_2d_traffic_sign", "路牌", "")
    CAMERA_2D_SPOT_DETECTION = (28, "camera_2d_spot_detection", "光斑", "")
    CITY_4D_LANE = (29, "city_4d_lane", "城市 4D Lane", "")
    D23_OBJECT_COMPLEMENT = (30, "d23_object_complement", "23d_object_complement", "")
    PARKING_D3_LANE = (31, "parking_d3_lane", "泊车3D车道线", "")
    UNKNOWN = (32, "3d_driving_segmentation", "3D 行车语义分割", "")

    def __init__(
        self, code: int, desc: str, chinese_desc: str, description: str = None
    ):
        self.code = code
        self.desc = desc
        self.chinese_desc = chinese_desc
        self.description = description

    @classmethod
    def _generate_mappings(cls):
        cls._code_to_desc = {member.code: member.desc for member in cls}
        cls._code_to_chinese_desc = {member.code: member.chinese_desc for member in cls}
        cls._desc_to_code = {member.desc: member.code for member in cls}
        cls._chinese_desc_to_code = {member.chinese_desc: member.code for member in cls}
        cls._code_to_enum = {member.code: member for member in cls}

    @classmethod
    def get_desc_by_code(cls, code):
        if not hasattr(cls, "_code_to_desc"):
            cls._generate_mappings()
        return cls._code_to_desc.get(code)

    @classmethod
    def get_chinese_desc_by_code(cls, code):
        if not hasattr(cls, "_code_to_chinese_desc"):
            cls._generate_mappings()
        return cls._code_to_chinese_desc.get(code)

    @classmethod
    def get_code_by_desc(cls, desc):
        if not hasattr(cls, "_desc_to_code"):
            cls._generate_mappings()
        return cls._desc_to_code.get(desc)

    @classmethod
    def get_code_by_chinese_desc(cls, chinese_desc):
        if not hasattr(cls, "_chinese_desc_to_code"):
            cls._generate_mappings()
        return cls._chinese_desc_to_code.get(chinese_desc)

    @classmethod
    def get_enum_by_code(cls, code):
        if not hasattr(cls, "_code_to_enum"):
            cls._generate_mappings()
        return cls._code_to_enum.get(code)

    @classmethod
    def list_codes(cls):
        return [member.code for member in cls]

    @classmethod
    def list_descs(cls):
        return [member.desc for member in cls]

    @classmethod
    def list_chinese_descs(cls):
        return [member.chinese_desc for member in cls]

    @classmethod
    def get_options(cls):
        return [{"label": member.chinese_desc, "value": member.code} for member in cls]
